import pickle
import numpy as np
import matplotlib.pyplot as plt
import math

PATHS = ["../node-data/"]
NODES = 100
BAR_MIN_PERC = 0.05
BAR_MAX_PERC = 0.95

#Read the simulator's complete output for a given node. ( Need the while loop since we build the pickled file with multiple calls to pickle.dump() )
def read_data_from_file(path,id):
    data = []
    filepath = path + str(id) + '.dat'
    with open(filepath) as f:
        while(1):
            try:
                data.extend(pickle.load(f))
            except EOFError:
                break #No more data
    return data

def main():
    legend = ["Adversarial", "Normal"]
    agg = []
    run_index = 0
    for path in PATHS:
        #Load node cost vectors
        costs = {}
        for x in xrange(NODES):
            costs[x] = read_data_from_file(path,x)
        # Just practicing dictionary comprehensions(doesn't work for old python)
        #costs = {k: read_data_from_file(path,k) for k in xrange(NODES)}

    #Use node 0
    cumulative = np.cumsum(np.array(costs[0]))
    
    fig = plt.figure()
    plt.plot(cumulative)
    plt.show() 
    

if __name__ =='__main__':
    main()
